home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / ODMemMgr / Sources / MemInit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-03  |  3.2 KB  |  146 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MemInit.cpp
  3.  
  4.     Contains:    CFM initializtion for Memory
  5.  
  6.     Owned by:    A. Michael Burbidge
  7.  
  8.     Copyright:    © 1994 - 1995-96 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.                  2/13/96    srf        Build variation for MacApp
  12.  
  13.         <16>      6/7/95    jpa        Removed old (pre-SLIM) SOM includes.
  14.                                     [1256901]
  15.         <15>      6/2/95    TJ        Included Gestalt.h
  16.         <14>      6/1/95    jpa        Restored <12>: Compute total system memory
  17.                                     at init time [1249619]
  18.         <13>     5/17/95    TJ        Backed out changes from previous checkin.
  19.         <11>     1/12/95    jpa        Strings.h --> TextUtils.h [1210936]
  20.         <10>     12/5/94    jpa        Nuked errant pragma lib_export's. [1195676]
  21.          <9>    10/24/94    jpa        Turn off validation
  22.          <8>    10/11/94    NP        1189812: Make Init routine pascal.
  23.          <7>     9/29/94    RA        1189812: Mods for 68K build.
  24.          <6>     9/14/94    jpa        Don't include UseRsrcM.h [1186692]
  25.          <5>      9/9/94    jpa        Added prototype & commented out initBlkPtr
  26.                                     to avoid warnings.
  27.          <4>     8/19/94    jpa        Call ODInitMemory at library init time
  28.                                     [1182106]
  29.          <3>     6/30/94    jpa        Added InitLibraryResources call.
  30.          <2>     6/23/94    NP        Clean up.
  31.          <1>     6/10/94    MB        first checked in
  32.     To Do:
  33.     In Progress:
  34.         
  35. */
  36.  
  37.  
  38. #ifndef __CODEFRAGMENTS__
  39. #include <CodeFragments.h>
  40. #endif
  41.  
  42. #ifndef _MEMMGR_
  43. #include "MemMgr.h"
  44. #endif
  45.  
  46. #ifndef _MEMDEBG_
  47. #include "MemDebg.h"
  48. #endif
  49.  
  50. #ifndef _MEMMGRPV_
  51. #include "MemMgrPv.h"
  52. #endif
  53.  
  54. #ifndef __GESTALT__
  55. #include <Gestalt.h>
  56. #endif
  57.  
  58. #ifndef __ERRORS__
  59. #include <Errors.h>
  60. #endif
  61.  
  62. #ifndef __PROCESSES__
  63. #include <Processes.h>
  64. #endif
  65.  
  66. #ifndef __TEXTUTILS__
  67. #include <TextUtils.h>
  68. #endif
  69.  
  70. #if !defined(qMacApp)
  71. #ifndef __SOM__
  72. #include <som.xh>
  73. #endif
  74. #endif
  75.  
  76. MMBoolean gHaveSOM;
  77.  
  78. size_t gTotalMemory;                // Declared in PlatfMem.h
  79.  
  80.  
  81. static OSErr
  82. GetProcessName( char name[] )
  83. {
  84.     name[0] = 0;
  85.     
  86.     ProcessSerialNumber psn;
  87.     psn.highLongOfPSN = 0;
  88.     psn.lowLongOfPSN = kCurrentProcess;
  89.     
  90.     ProcessInfoRec info;
  91.     info.processInfoLength = sizeof(info);
  92.     info.processName = (StringPtr) name;
  93.     info.processAppSpec = kMMNULL;
  94.     OSErr err= GetProcessInformation(&psn,&info);
  95.     if( !err )
  96.         p2cstr((StringPtr)name);
  97.     return err;
  98. }
  99.  
  100.  
  101. extern "C" {
  102.     pascal OSErr MemoryCFMInit( CFragInitBlockPtr );
  103.     static void* MMCAllocate( size_t size, size_t n );
  104. }
  105.  
  106. static void* MMCAllocate( size_t size, size_t n )
  107. {
  108.     return MMAllocateClear(n*size);
  109. }
  110.  
  111.  
  112. pascal OSErr MemoryCFMInit( CFragInitBlockPtr )
  113. {
  114. #if MM_DEBUG
  115.     long result;
  116.     if( Gestalt(gestaltLogicalRAMSize,(long*)&gTotalMemory) != noErr )
  117.         gTotalMemory = 0x80000000;    // bogus default value
  118.     if( Gestalt(gestaltVMAttr,&result) == noErr && (result&1) )
  119.         gTotalMemory <<= 1;            // Use double logical RAM size if VM on
  120.                                     // since code fragments get loaded above it
  121. #endif
  122.  
  123.     // Create a default heap:
  124.     char name[256];
  125.     GetProcessName(name);
  126.     strcat(name," default heap"); // For debugging only so hardcoded string is OK
  127.     MemHeap *heap = MMNewHeap(kMMTempMemory,200*1024L,32*1024L,name);
  128.     if( !heap )
  129.         return memFullErr;
  130.     MMSetDefaultHeap(heap);
  131.     
  132. #if !defined(qMacApp)
  133.     gHaveSOM = ((void*)&SOMMalloc != (void*)kUnresolvedCFragSymbolAddress);    // Is SOM installed?
  134.  
  135.     if( gHaveSOM ) {
  136.         SOMMalloc = &MMAllocate;
  137.         SOMCalloc = &MMCAllocate;
  138.         SOMRealloc= &MMReallocate;
  139.         SOMFree   = &MMFree;
  140.     }
  141. #endif
  142.     
  143.     return noErr;
  144. }
  145.  
  146.